class of the Java method where the callback is "Com/itheima/callbackjava/jni"
② finding a method object from a byte-code object
Jmethodid (getmethodid) (jnienv, jclass, const char, const char);
The second parameter bytecode object The third parameter to reflect the calling Java method name fourth parameter to reflect the calling Java method signature
Get method Signature: Javap-s The full class name of the class to get the method signature/bin/classes run JAVAP
execute () method in this class. 2. The class object is obtained by calling the classes property through the name For example:classClass1 getting the reflected objectPackage Com.qianfeng.reflect;import com.qianfeng.domain.person;/* Reflection: Get a member of a class or class dynamically, and use a class or member of a class to get a class bytecode file object in a way ( Class name of the. Class) */public class ReflectDemo1 {public ReflectDemo1 () {//TODO auto-generated constructor stub}public
be invoked directly from the Java object passed by JNI.Jobject obj = (*env)->allocobject (Env,claz);When the callback method is not in the same class as the local method, you need to manually create a Java object from the byte-code object you just created.The way to tune Java back through this objectIt is important to note that if you are creating a callback method for an Activity object that also contains context this method does not work!!! return
, IllegalArgumentException, invocationtargetexception {//person person = new Person ("Little Red", +); //Get bytecode File object---person.classclass"Com.reflect.Person");//Get the object of type constructor that the constructor method belongs toconstructorint. Class);//using construction methods to create objects--the ability to create objects with constructorPerson person = (person) constructor.newinstance ("Little Red", -); System. out. println (person);}3) Dynamically create objects a
;System.out.println (OTD1==OTD2); FalseSystem.out.println (Otd1.equals (OTD2)); The return is always False if not written.There is no absolute relationship between the Hashcode method and the Equals method.Refer to the source code of the note description, in the actual use as far as possible to overwrite both methods, to maintain consistencyPublic final native classThe GetClass method is a local method that invokes the underlying code and returns an instance of the class object corresponding to
methods of the class, for any one object,Can call its methods and properties, which dynamically acquires methods and properties, and dynamically invokes the functions of methods and properties , called the Java Reflection mechanism.2. Reflection mechanism what it can doThe reflection mechanism mainly provides the following functions:1: At run time, determine the class to which any object belongs.2: Constructs an object of any class at run time.3: At run time, determine the member variables and
, instantiationexception {
class Claz = dbcrud.class;//Gets the bytecode file object
//Gets all the methods in the class and the parent class
method[] methods = Claz.getmethods ();
For (methods M:methods) {
///Whether the method uses @mytest this annotation
// Boolean boo = M.isannotationpresent (mytest.class); System.out.println (M.getname () + "= =" +boo);//All is false the default ann
An instance of the Java.lang.Class class represents a. class document that is loaded when the Java application runs. Its constructor: Private Class () {} indicates that we cannot create a class object, the class object is automatically generated by the JVM, and each. Class document is loaded, and the JVM automatically generates the corresponding class object. When to load. class files into memory 1, with Class.forName () or ClassLoader (class Claz = F
The field is similar to the previous construction method and behavior method;
Package javainvokefiled;Import Java.lang.reflect.Field; /*** Reflection Get Field* @author Administrator**/Class filed{public String name;private int age;private int number;public String password; Public Filed () {}} public class Invokefiled {/*** Get the field method and the previous fetch constructor and method are very similar. Getfileds (): Gets all public-decorated fields and field rules that inherit from the par
(optional) if the local Method and the java Method to be called back are in the same class, you can directly call the created Method using the java object passed by jni.
Jobject obj = (* env)-> AllocObject (env, claz );
When the callback method is not in the same class as the local method, you must manually create a java object through the newly created bytecode object.
Then the method for calling java back and forth through this object
Note that if
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.